package com.lrkj.payfee.service.impl;

import java.math.BigDecimal;
import java.util.List;
import com.lrkj.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lrkj.payfee.mapper.AgainstRecordMapper;
import com.lrkj.payfee.domain.AgainstRecord;
import com.lrkj.payfee.service.IAgainstRecordService;

/**
 * 冲抵记录Service业务层处理
 *
 * @author yajun_ren
 * @date 2022-03-10
 */
@Service
public class AgainstRecordServiceImpl implements IAgainstRecordService
{
    @Autowired
    private AgainstRecordMapper againstRecordMapper;

    /**
     * 查询冲抵记录
     *
     * @param receiptId 冲抵记录ID
     * @return 冲抵记录
     */
    @Override
    public AgainstRecord selectAgainstRecordById(String receiptId)
    {
        return againstRecordMapper.selectAgainstRecordById(receiptId);
    }

    /**
     * 查询冲抵记录列表
     *
     * @param againstRecord 冲抵记录
     * @return 冲抵记录
     */
    @Override
    public List<AgainstRecord> selectAgainstRecordList(AgainstRecord againstRecord)
    {
        return againstRecordMapper.selectAgainstRecordList(againstRecord);
    }

    /**
     * 新增冲抵记录
     *
     * @param againstRecord 冲抵记录
     * @return 结果
     */
    @Override
    public int insertAgainstRecord(AgainstRecord againstRecord)
    {
        againstRecord.setCreateTime(DateUtils.getNowDate());
        return againstRecordMapper.insertAgainstRecord(againstRecord);
    }

    /**
     * 修改冲抵记录
     *
     * @param againstRecord 冲抵记录
     * @return 结果
     */
    @Override
    public int updateAgainstRecord(AgainstRecord againstRecord)
    {
        return againstRecordMapper.updateAgainstRecord(againstRecord);
    }

    /**
     * 批量删除冲抵记录
     *
     * @param receiptIds 需要删除的冲抵记录ID
     * @return 结果
     */
    @Override
    public int deleteAgainstRecordByIds(String[] receiptIds)
    {
        return againstRecordMapper.deleteAgainstRecordByIds(receiptIds);
    }

    /**
     * 删除冲抵记录信息
     *
     * @param receiptId 冲抵记录ID
     * @return 结果
     */
    @Override
    public int deleteAgainstRecordById(String receiptId)
    {
        return againstRecordMapper.deleteAgainstRecordById(receiptId);
    }
    /**
     * 批量新增冲抵记录信息
     *
     * @param againstRecords 冲抵记录对象
     */
    public int batchAddData(List<AgainstRecord> againstRecords)
    {
           return againstRecordMapper.batchAddData(againstRecords);
    }


    //新增冲抵记录
    public AgainstRecord createAgainstRecord(String madvanceReceiptId, String businessId, String businessType,String businessNo, BigDecimal amountAmount ){
        AgainstRecord record = new AgainstRecord();
        record.setMadvanceReceiptId(madvanceReceiptId);//预收单ID
        record.setBusinessId(businessId); //业务ID
        record.setBusinessType(businessType); //业务类型
        record.setBusinessNo(businessNo);//业务单号
        record.setCreateTime(DateUtils.getNowDate()); //使用时间
        record.setAmountAmount(amountAmount); //使用金额
        againstRecordMapper.insertAgainstRecord(record);
        return record;
    }
}
